package com.mybatisplus.sunpineshop.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;

/**
 * @Author GongXl
 * @Description WebSocket聊天室
 * @Date 2021/2/21 22:00
 * @Param 
 * @return 
 **/
@Controller
public class GreetingController {
    @Autowired
    private SimpMessagingTemplate simpMessagingTemplate;
    @MessageMapping("/hello")
    @SendTo("/topic/greetings")//将处理过的消息转发到broker,有broker广播
    public Message greeting(Message message){
        simpMessagingTemplate.convertAndSend("/topic/greetings",message);
       return message;
    }
    /**
     * @Author GongXl
     * @Description 此借用模板也可发送
     * @Date 2021/2/21 22:11
     * @Param [message]
     * @return void
     **/
    @MessageMapping("/hello2")
    public void greeting2(Message message){
        simpMessagingTemplate.convertAndSend("/topic/greetings",message);
    }

}

